package com.jhgsys.internal.incentive.controller;

import com.jhgsys.internal.common.annotation.Log;
import com.jhgsys.internal.common.controller.BaseController;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.entity.FebsResponse;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.exception.FebsException;
import com.jhgsys.internal.common.utils.FebsUtil;
import com.jhgsys.internal.incentive.entity.IncentiveRewardAuditRecord;
import com.jhgsys.internal.incentive.service.IIncentiveRewardAuditRecordService;
import com.wuwenze.poi.ExcelKit;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
import javax.validation.constraints.NotBlank;
import java.util.Date;

/**
 * 安全奖励审核记录 Controller
 *
 * @author wanghjw
 * @date 2024-09-03 14:08:27
 */
@Slf4j
@Validated
@Controller
public class IncentiveRewardAuditRecordController extends BaseController {

    @Autowired
    private IIncentiveRewardAuditRecordService incentiveRewardAuditRecordService;

    @GetMapping(FebsConstant.VIEW_PREFIX + "incentiveRewardAuditRecord")
    @RequiresPermissions("incentiveRewardAuditRecord:view")
    public String incentiveRewardAuditRecordIndex(){
        return FebsUtil.view("incentive/incentiveRewardAuditRecord/incentiveRewardAuditRecordList");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "incentiveRewardAuditRecord/add")
    @RequiresPermissions("incentiveRewardAuditRecord:add")
    public String incentiveRewardAuditRecordAdd(){
        return FebsUtil.view("incentive/incentiveRewardAuditRecord/incentiveRewardAuditRecordEdit");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "incentiveRewardAuditRecord/update/{id}")
    @RequiresPermissions("incentiveRewardAuditRecord:edit")
    public String incentiveRewardAuditRecordUpdate(Model model, @PathVariable("id") String id){
        model.addAttribute("incentiveRewardAuditRecord", incentiveRewardAuditRecordService.findIncentiveRewardAuditRecordById(id));
        return FebsUtil.view("incentive/incentiveRewardAuditRecord/incentiveRewardAuditRecordEdit");
    }

    /**
     * 查询（所有）
     * @author wanghjw
     * @date 2024-09-03 14:08:27
     */
    @GetMapping("incentiveRewardAuditRecord")
    @ResponseBody
    @RequiresPermissions("incentiveRewardAuditRecord:view")
    public FebsResponse getAllIncentiveRewardAuditRecords(IncentiveRewardAuditRecord incentiveRewardAuditRecord) {
        return new FebsResponse().success().data(incentiveRewardAuditRecordService.findIncentiveRewardAuditRecordList(incentiveRewardAuditRecord));
    }

    /**
     * 查询（分页）
     * @author wanghjw
     * @date 2024-09-03 14:08:27
     */
    @GetMapping("incentiveRewardAuditRecord/list")
    @ResponseBody
    @RequiresPermissions("incentiveRewardAuditRecord:view")
    public FebsResponse incentiveRewardAuditRecordList(QueryRequest request, IncentiveRewardAuditRecord incentiveRewardAuditRecord) {
        Map<String, Object> dataTable = getDataTable(this.incentiveRewardAuditRecordService.findIncentiveRewardAuditRecordPage(request, incentiveRewardAuditRecord));
        return new FebsResponse().success().data(dataTable);
    }

    /**
     * 新增 IncentiveRewardAuditRecord
     * @author wanghjw
     * @date 2024-09-03 14:08:27
     */
    @Log("新增IncentiveRewardAuditRecord")
    @PostMapping("incentiveRewardAuditRecord")
    @ResponseBody
    @RequiresPermissions("incentiveRewardAuditRecord:add")
    public FebsResponse addIncentiveRewardAuditRecord(@Valid IncentiveRewardAuditRecord incentiveRewardAuditRecord) throws FebsException {
        try {
            incentiveRewardAuditRecord.setCreatedBy(getCurrentUser().getUserName());
            this.incentiveRewardAuditRecordService.createIncentiveRewardAuditRecord(incentiveRewardAuditRecord);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "新增IncentiveRewardAuditRecord失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

    /**
     * 逻辑删除 IncentiveRewardAuditRecord
     * @author wanghjw
     * @date 2024-09-03 14:08:27
     */
    @Log("逻辑删除IncentiveRewardAuditRecord")
    @GetMapping("incentiveRewardAuditRecord/delete/{id}")
    @ResponseBody
    @RequiresPermissions("incentiveRewardAuditRecord:delete")
    public FebsResponse deleteIncentiveRewardAuditRecord(@PathVariable("id") String incentiveRewardAuditRecordIds) throws FebsException {
        try {
            IncentiveRewardAuditRecord incentiveRewardAuditRecord = new IncentiveRewardAuditRecord();
            incentiveRewardAuditRecord.setDeletedBy(getCurrentUser().getUserName());
            incentiveRewardAuditRecord.setDeletedTime(new Date());
            incentiveRewardAuditRecord.setDeletedFlg(FebsConstant.INVALID);
            this.incentiveRewardAuditRecordService.deleteIncentiveRewardAuditRecord(incentiveRewardAuditRecord,incentiveRewardAuditRecordIds);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "删除IncentiveRewardAuditRecord失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

    /**
    * 物理删除 IncentiveRewardAuditRecord
    * @author wanghjw
    * @date 2024-09-03 14:08:27
    */
    @Log("物理删除IncentiveRewardAuditRecord")
    @GetMapping("incentiveRewardAuditRecord/physicallyDelete/{id}")
    @ResponseBody
    @RequiresPermissions("incentiveRewardAuditRecord:delete")
    public FebsResponse physicallyDeleteIncentiveRewardAuditRecord(@PathVariable("id") String incentiveRewardAuditRecordIds) throws FebsException {
        try {
            this.incentiveRewardAuditRecordService.physicallyDeleteIncentiveRewardAuditRecord(incentiveRewardAuditRecordIds);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "删除IncentiveRewardAuditRecord失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

    /**
     * 修改 IncentiveRewardAuditRecord
     * @author wanghjw
     * @date 2024-09-03 14:08:27
     */
    @Log("修改IncentiveRewardAuditRecord")
    @PostMapping("incentiveRewardAuditRecord/update")
    @ResponseBody
    @RequiresPermissions("incentiveRewardAuditRecord:edit")
    public FebsResponse updateIncentiveRewardAuditRecord(IncentiveRewardAuditRecord incentiveRewardAuditRecord) throws FebsException {
        try {
            incentiveRewardAuditRecord.setUpdatedBy(getCurrentUser().getUserName());
            this.incentiveRewardAuditRecordService.updateIncentiveRewardAuditRecord(incentiveRewardAuditRecord);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "修改IncentiveRewardAuditRecord失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

}
